<?php
/**
 * 维修记录相关接口请求参数验证器
 * Created by PhpStorm.
 * User: LRChang
 * Date: 2018/06/01
 * Time: 19:02
 * Mail: hjklrchang@qq.com
 */

namespace app\adminapi\validate;

use app\base\validate\BaseValidate;

class MaintenanceRecordValidate extends BaseValidate
{
    protected $rule = [
        'page' => 'isPositiveInt',
        'pagenum' => 'isPositiveInt',
//        'fields' => '',
        'where_json' => 'isWhereJson',

        'maintenance_record_id' => 'require|isPositiveInt',
        'maintenance_id' => 'require|isPositiveInt',
        'company_id' => 'require|isPositiveInt',
        'car_id'=>'require|isPositiveInt',
        'numbers'=>'require|max:100',
        'start_date'=>'require|dateFormat:Y-m-d',
        'end_date'=>'require|dateFormat:Y-m-d',
        'price'=>'>=:0',
        'address'=>'max:200',
        'leader'=>'require|max:20',
        'km'=>'>=:0',
        'service_type'=>'in:0,1,2',
        'service_img'=>'max:255',
//        'ps'=>'',
        'remind'=>'max:100',

        'maintenance_record_ids' => 'require|checkIDs',
    ];

    // 默认值
    protected $default = [
        'page' => 1,
        'pagenum' => 20,
        'where_json' => '',
        'fields' => '*',
    ];

    protected $message = [
        'page.isPositiveInt' => '页数只能为正整数',
        'pagenum.isPositiveInt' => '每页数量只能为正整数',
        'fields.isNotEmpty' => '字段不能为空',
        'where_json.isWhereJson' => '不是合法的json字符串',
    ];

    protected $scene = [
        'list' => ['page' ,'pagenum', 'fields', 'where_json'],
        'add' => [
            'maintenance_id',
            'company_id',
            'car_id',
            'numbers',
            'start_date',
            'end_date',
            'price',
            'leader',
            'km',
            'service_type',
            'service_img',
            'ps',
            'remind',
        ],
        'edit' => [
            'maintenance_record_id',
            'maintenance_id',
            'company_id',
            'numbers',
            'start_date',
            'end_date',
            'price',
            'address',
            'leader',
            'km',
            'service_type',
            'service_img',
            'ps',
            'remind',
        ],
        'delete' => [ 'maintenance_record_ids' ],
    ];
}